package DataReadWrite;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class ReadData {

	private String[][] parsing_data;
	
	private int col;
	private int row;
	
	public ReadData(String file_path , int col , int row){
		this.col = col;
		this.row = row;
		
		parsing_data = new String[col][row];
		
		File file = new File(file_path);
		
		try {
			
			FileReader filereader = new FileReader(file);
			BufferedReader reader = new BufferedReader(filereader);
		
			String line = null;
			int myline = 0;
			
			while( (line = reader.readLine() ) != null ){
				//System.out.println(line);
				String value[] = line.split("\t");
				
				for(int i = 0 ; i < value.length ; i++ ){
				//	System.out.print(i + " : " + value[i]+" ");
					parsing_data[myline][i] = value[i];
				}
				//System.out.println();
				myline++;
			}
			
			reader.close();
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public double[][] get_data(){
		
		double result[][] = new double[col][row];
		
		for(int i = 0 ; i < col ; i++){
			for(int j = 0 ; j < row ; j++){
				result[i][j] = Double.parseDouble(parsing_data[i][j]);
		//		System.out.print(result[i][j]+" ");
			}
		//	System.out.println();
		}
		
		return result;
	}
}
